function mapChildren(children, func, context) {
    //TODO实现此mapChildren方法
    if (children === null) {
        return children;
    }
    let array = []
    let result = []
    let index = 0
    getChildArray(children, array)
    handleChildArray(result, array, func, context, index)
    return result
}

//获取儿子组件数组
function getChildArray(children, array) {
    if (Array.isArray(children)) {
        children.forEach(ele => {
            if (Array.isArray(ele)) {
                return getArray(ele, array)
            }
            array.push(ele)
        })
    } else {
        array.push(children)
    }
}

//获取组件方法
function handleChildArray(result, array, func, context, index) {
    for (let i = 0; i < array.length; i++) {
        const item = array[i];
        const res = func.call(context, item, index++)
        if (Array.isArray(res) && res.length) {
            res.forEach(ele => {
                result.push(ele)
            })
        } else {
            result.push(res)
        }
    }
}



export {
    mapChildren as map,
};